<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>微信公众号小程序实战开发vue3+nodejs+koa2+mysql+nginx阿里云部署教程 | 波波科技文档合集</title>
    <meta name="description" content="Just playing around.">
    <link rel="stylesheet" href="/bobokejiDoc/assets/style.ba36feea.css">
    <link rel="modulepreload" href="/bobokejiDoc/assets/chunks/VPAlgoliaSearchBox.277a18d8.js">
    <link rel="modulepreload" href="/bobokejiDoc/assets/app.d51e1bd1.js">
    <link rel="modulepreload" href="/bobokejiDoc/assets/tbtext.md.9db7909d.lean.js">
    
    <script id="check-dark-light">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-c6a644e1><!--[--><!--]--><!--[--><span tabindex="-1" data-v-151f2593></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-151f2593> Skip to content </a><!--]--><!----><header class="VPNav" data-v-c6a644e1 data-v-a71a30f1><div class="VPNavBar has-sidebar" data-v-a71a30f1 data-v-6f1d18b5><div class="container" data-v-6f1d18b5><div class="VPNavBarTitle has-sidebar" data-v-6f1d18b5 data-v-d5925166><a class="title" href="/bobokejiDoc/" data-v-d5925166><!--[--><!--]--><!----><!--[-->波波科技文档合集<!--]--><!--[--><!--]--></a></div><div class="content" data-v-6f1d18b5><!--[--><!--]--><div class="VPNavBarSearch search" data-v-6f1d18b5 style="--5943dbe8:&#39;Meta&#39;;"><div id="docsearch"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg class="DocSearch-Search-Icon" width="20" height="20" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div></div><!----><!----><div class="VPNavBarAppearance appearance" data-v-6f1d18b5 data-v-a3e7452b><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" aria-label="toggle dark mode" aria-checked="false" data-v-a3e7452b data-v-31fdf26f data-v-eba7420e><span class="check" data-v-eba7420e><span class="icon" data-v-eba7420e><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-31fdf26f><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-31fdf26f><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><!----><div class="VPFlyout VPNavBarExtra extra" data-v-6f1d18b5 data-v-e4361c82 data-v-6ffb57d3><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-6ffb57d3><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-6ffb57d3><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-6ffb57d3><div class="VPMenu" data-v-6ffb57d3 data-v-1c5d0cfc><!----><!--[--><!--[--><!----><div class="group" data-v-e4361c82><div class="item appearance" data-v-e4361c82><p class="label" data-v-e4361c82>Appearance</p><div class="appearance-action" data-v-e4361c82><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" aria-label="toggle dark mode" aria-checked="false" data-v-e4361c82 data-v-31fdf26f data-v-eba7420e><span class="check" data-v-eba7420e><span class="icon" data-v-eba7420e><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-31fdf26f><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-31fdf26f><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><!----><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-6f1d18b5 data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div><!----></header><div class="VPLocalNav" data-v-c6a644e1 data-v-aac27d5e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-aac27d5e><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-aac27d5e><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-aac27d5e>Menu</span></button><a class="top-link" href="#" data-v-aac27d5e> Return to top </a></div><aside class="VPSidebar" data-v-c6a644e1 data-v-0f582cdc><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-0f582cdc><span class="visually-hidden" id="sidebar-aria-label" data-v-0f582cdc> Sidebar Navigation </span><!--[--><div class="group" data-v-0f582cdc><section class="VPSidebarGroup" data-v-0f582cdc data-v-6e45c352><div class="title" data-v-6e45c352><h2 class="title-text" data-v-6e45c352>文档目录</h2><div class="action" data-v-6e45c352><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0 0 24 24" class="icon minus" data-v-6e45c352><path d="M19,2H5C3.3,2,2,3.3,2,5v14c0,1.7,1.3,3,3,3h14c1.7,0,3-1.3,3-3V5C22,3.3,20.7,2,19,2zM20,19c0,0.6-0.4,1-1,1H5c-0.6,0-1-0.4-1-1V5c0-0.6,0.4-1,1-1h14c0.6,0,1,0.4,1,1V19z"></path><path d="M16,11H8c-0.6,0-1,0.4-1,1s0.4,1,1,1h8c0.6,0,1-0.4,1-1S16.6,11,16,11z"></path></svg><svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24" class="icon plus" data-v-6e45c352><path d="M19,2H5C3.3,2,2,3.3,2,5v14c0,1.7,1.3,3,3,3h14c1.7,0,3-1.3,3-3V5C22,3.3,20.7,2,19,2z M20,19c0,0.6-0.4,1-1,1H5c-0.6,0-1-0.4-1-1V5c0-0.6,0.4-1,1-1h14c0.6,0,1,0.4,1,1V19z"></path><path d="M16,11h-3V8c0-0.6-0.4-1-1-1s-1,0.4-1,1v3H8c-0.6,0-1,0.4-1,1s0.4,1,1,1h3v3c0,0.6,0.4,1,1,1s1-0.4,1-1v-3h3c0.6,0,1-0.4,1-1S16.6,11,16,11z"></path></svg></div></div><div class="items" data-v-6e45c352><!--[--><!--[--><a class="VPLink link link active" href="/bobokejiDoc/tbtext.html" style="padding-left:0px;" data-v-36b976d1 data-v-3c355974><!--[--><span class="link-text" data-v-36b976d1>公众号开发「淘宝」返现系统</span><!--]--><!----></a><!----><!--]--><!--[--><a class="VPLink link link" href="/bobokejiDoc/jdtext.html" style="padding-left:0px;" data-v-36b976d1 data-v-3c355974><!--[--><span class="link-text" data-v-36b976d1>公众号开发「京东」返现系统</span><!--]--><!----></a><!----><!--]--><!--[--><a class="VPLink link link" href="/bobokejiDoc/minpro.html" style="padding-left:0px;" data-v-36b976d1 data-v-3c355974><!--[--><span class="link-text" data-v-36b976d1>微信小程序开发</span><!--]--><!----></a><!----><!--]--><!--]--></div></section></div><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-c6a644e1 data-v-c95df128><div class="VPDoc has-sidebar has-aside" data-v-c95df128 data-v-37ebe389><div class="container" data-v-37ebe389><div class="aside" data-v-37ebe389><div class="aside-curtain" data-v-37ebe389></div><div class="aside-container" data-v-37ebe389><div class="aside-content" data-v-37ebe389><div class="VPDocAside" data-v-37ebe389 data-v-afc4c1a1><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" data-v-afc4c1a1 data-v-2865c0b0><div class="content" data-v-2865c0b0><div class="outline-marker" data-v-2865c0b0></div><div class="outline-title" data-v-2865c0b0>On this page</div><nav aria-labelledby="doc-outline-aria-label" data-v-2865c0b0><span class="visually-hidden" id="doc-outline-aria-label" data-v-2865c0b0> Table of Contents for current page </span><ul class="root" data-v-2865c0b0 data-v-1188541a><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-afc4c1a1></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-37ebe389><div class="content-container" data-v-37ebe389><!--[--><!--]--><main class="main" data-v-37ebe389><div style="position:relative;" class="vp-doc _bobokejiDoc_tbtext" data-v-37ebe389><div><h1 id="微信公众号小程序实战开发vue3-nodejs-koa2-mysql-nginx阿里云部署教程" tabindex="-1">微信公众号小程序实战开发vue3+nodejs+koa2+mysql+nginx阿里云部署教程 <a class="header-anchor" href="#微信公众号小程序实战开发vue3-nodejs-koa2-mysql-nginx阿里云部署教程" aria-hidden="true">#</a></h1><blockquote><p>本课程通过开发微信公众号的实战学习，对接淘宝客系统开发出一套微信公众号自动找淘宝、天猫内部优惠券的系统，同时打通微信公众号对接小程序的云开发。使用到的技术栈有：vue3 + nodejs + koa2 + nginx服务器https后台部署 + mysql数据库等</p></blockquote><h2 id="第一课-课程介绍" tabindex="-1">第一课 课程介绍 <a class="header-anchor" href="#第一课-课程介绍" aria-hidden="true">#</a></h2><h3 id="一、课程背景及痛点" tabindex="-1">一、课程背景及痛点 <a class="header-anchor" href="#一、课程背景及痛点" aria-hidden="true">#</a></h3><p>开发本课程目的是用javaScript开发一套可以实战运营的微信公众号和小程序系统，让前端开发的初学者甚至有经验的开发者学到最新的前端知识的同时能开发一套属于自己的能够上线运营的实战项目</p><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">课程面向的学习者：</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">、有前端基础的同学、从事前端开发行业的童鞋学习面试展示</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;">、完全没有基础的同学也可以学习，最终部署自己公众号，实现运营盈利。</span></span>
<span class="line"></span></code></pre></div><h3 id="二、课程能学到什么？" tabindex="-1">二、课程能学到什么？ <a class="header-anchor" href="#二、课程能学到什么？" aria-hidden="true">#</a></h3><ol><li><p>学习微信公众号的开发</p></li><li><p>学习小程序云开发</p></li><li><p>掌握vue3 + elementPlus UI + TypeScript前端框架的使用</p></li><li><p>掌握使用 nodejs + koa2 + ejs 开发后台接口和ssr服务端渲染页面</p></li><li><p>熟练掌握基本的nginx + https 的后台服务部署</p></li><li><p>熟悉nodejs+mysql数据库的使用</p></li></ol><h3 id="三、学完课程能达到的目标" tabindex="-1">三、学完课程能达到的目标 <a class="header-anchor" href="#三、学完课程能达到的目标" aria-hidden="true">#</a></h3><ol><li><p>能够熟练开发微信公众号、小程序云开发</p></li><li><p>能够独立把自己开发的项目部署到公有云上，生产环境运行</p></li><li><p>掌握淘宝天猫优惠券api的调用</p></li></ol><h3 id="四、项目演示" tabindex="-1">四、项目演示 <a class="header-anchor" href="#四、项目演示" aria-hidden="true">#</a></h3><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-03-29-%E9%A1%B9%E7%9B%AE%E6%BC%94%E7%A4%BA.jpg" alt=""></p><h3 id="五、学习资料领取以及课后交流" tabindex="-1">五、学习资料领取以及课后交流 <a class="header-anchor" href="#五、学习资料领取以及课后交流" aria-hidden="true">#</a></h3><p>1、微信公众号<code>波波科技网络工作室</code> 回复 <code>学习</code></p><p>2、微信小程序<code>波波科技网络工作室</code>找<code>客服小哥哥</code>索取学习资料</p><p>3、VX：bobokeji521</p><h2 id="第二课-项目准备环境搭建" tabindex="-1">第二课 项目准备环境搭建 <a class="header-anchor" href="#第二课-项目准备环境搭建" aria-hidden="true">#</a></h2><blockquote><p>本节课带大家搭建微信公众号开发的环境（nodejs）以及下载好开发过程中用到的工具软件(开发工具vscode、内网穿透工具ngrok)</p></blockquote><h3 id="一、-vscode代码编辑软件下载" tabindex="-1">一、 vscode代码编辑软件下载 <a class="header-anchor" href="#一、-vscode代码编辑软件下载" aria-hidden="true">#</a></h3><p>根据自己的电脑系统下载对应版本即可。<a href="https://code.visualstudio.com/" target="_blank" rel="noreferrer">vscode官网地址</a></p><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-03-161955.png" alt=""></p><h3 id="二、nodejs-下载" tabindex="-1">二、nodejs 下载 <a class="header-anchor" href="#二、nodejs-下载" aria-hidden="true">#</a></h3><ol><li>直接去nodejs的官网安装自己的电脑系统下载并且安装好即可<a href="http://nodejs.cn/download/" target="_blank" rel="noreferrer">下载 | Node.js 中文网</a></li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-03-160630.png" alt=""></p><ol start="2"><li>安装完成后打开命令终端输入<code>node -v</code>命令，如果能正确返回版本号那就说明安装成功</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-03-161539.png" alt=""></p><ol start="3"><li>用nodejs简单写一个本地服务</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> http </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">http</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">http</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">createServer</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">req</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;">//设置http响应头,状态码:200，文件类型:html,字符集:utf8</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">writeHead</span><span style="color:#F07178;">(</span><span style="color:#F78C6C;">200</span><span style="color:#89DDFF;">,{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">Content-Type</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">text/html; charset=utf-8</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">}</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">;</span><span style="color:#676E95;">/*响应状态码和响应头*/</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">write</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">波波科技网络工作室</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">;</span><span style="color:#F07178;"> </span><span style="color:#676E95;">/*响应数据*/</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">end</span><span style="color:#F07178;">()</span><span style="color:#89DDFF;">;</span><span style="color:#F07178;"> </span><span style="color:#676E95;">/*结束响应*/</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">listen</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">8080</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span></code></pre></div><h3 id="三、内网穿透工具的使用ngrok的使用" tabindex="-1">三、内网穿透工具的使用ngrok的使用 <a class="header-anchor" href="#三、内网穿透工具的使用ngrok的使用" aria-hidden="true">#</a></h3><ol><li><p>注册用户，下载对应版本的ngrok的软件。<a href="https://dashboard.ngrok.com/" target="_blank" rel="noreferrer">ngrok官网地址</a></p><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-04-034143.png" alt=""></p></li><li><p>在你本机电脑配置当前用户的鉴权令牌，执行如下命令，⚠️注意每个账户的令牌不一样，直接从官网拷贝就行<img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-04-040220.png" alt=""></p></li><li><p>邮箱校验，点击<code>设置</code>-&gt;点击<code>账号</code>-&gt;点击<code>邮箱校验</code>，或者直接点击<a href="https://dashboard.ngrok.com/user/settings" target="_blank" rel="noreferrer">邮箱校验地址</a><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-04-041000.png" alt=""></p></li><li><p>开启内网穿透：mac系统的需要找到第一步下载软件的地址执行如下命令，windows系统直接双击第一步的软件即可</p></li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#89DDFF;">./</span><span style="color:#A6ACCD;">ngrok http </span><span style="color:#F78C6C;">8080</span></span>
<span class="line"></span></code></pre></div><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-04-042313.png" alt=""></p><h3 id="四、微信公众号的申请" tabindex="-1">四、微信公众号的申请 <a class="header-anchor" href="#四、微信公众号的申请" aria-hidden="true">#</a></h3><ol><li><p>进入<a href="https://mp.weixin.qq.com/" target="_blank" rel="noreferrer">微信公众平台</a>申请订阅号类型的微信公众号<img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-04-111916.png" alt=""></p></li><li><p>进入开发者工具查看开发文档<img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-04-112815.png" alt=""></p></li></ol><h3 id="第三课-微信公众号开发配置" tabindex="-1">第三课 微信公众号开发配置 <a class="header-anchor" href="#第三课-微信公众号开发配置" aria-hidden="true">#</a></h3><blockquote><p>本节课带大家熟悉微信公众号的开发模式以及使用koa搭建后台开发，配置微信公众号开发服务器，使用crypto模块进行SHA1加密验证微信公众号服务器。</p></blockquote><h3 id="一、微信公众号开发模式介绍" tabindex="-1">一、微信公众号开发模式介绍 <a class="header-anchor" href="#一、微信公众号开发模式介绍" aria-hidden="true">#</a></h3><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-04-14-142257.png" alt=""></p><h3 id="二、初始化项目文件、koa开发服务器" tabindex="-1">二、初始化项目文件、koa开发服务器 <a class="header-anchor" href="#二、初始化项目文件、koa开发服务器" aria-hidden="true">#</a></h3><ol><li>初始化项目</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm init</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>安装koa模块</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install koa</span></span>
<span class="line"></span></code></pre></div><h3 id="三、开发配置、验证微信服务器消息" tabindex="-1">三、开发配置、验证微信服务器消息 <a class="header-anchor" href="#三、开发配置、验证微信服务器消息" aria-hidden="true">#</a></h3><ol><li><p>配置服务器地址的url</p></li><li><p>安装crpto模块<code>npm install crypto</code>，验证请求是来自微信服务器</p></li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koa </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;"> createHash </span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">crypto</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> app </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">koa</span><span style="color:#A6ACCD;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">const</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">token</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">abcefg123</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">const</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;">signature</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">echostr</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">timestamp</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">nonce</span><span style="color:#89DDFF;">}</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">query</span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;">// 将token、timestamp、nonce三个参数进行字典序排序</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">const</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">stringArray</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> [</span><span style="color:#A6ACCD;">timestamp</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">nonce</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">token</span><span style="color:#F07178;">]</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">const</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resultArray</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">stringArray</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">sort</span><span style="color:#F07178;">()</span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;">// 将三个参数字符串拼接成一个字符串进行sha1加密</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">const</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resultString</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resultArray</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">join</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">const</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">hashResut</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">createHash</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">sha1</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">update</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">resultString</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">digest</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">hex</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">hashResut===&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">hashResut</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">signature===&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">signature</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">echostr</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">listen</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">serve is on at 8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span></code></pre></div><h2 id="第四课-获取并刷新微信公众号accesstoken" tabindex="-1">第四课 获取并刷新微信公众号accessToken <a class="header-anchor" href="#第四课-获取并刷新微信公众号accesstoken" aria-hidden="true">#</a></h2><blockquote><p>获取微信公众号的accessToken存储到服务器，并且定时刷新accessToken</p></blockquote><h3 id="一、后台定时获取并刷新微信公众号access-token" tabindex="-1">一、后台定时获取并刷新微信公众号Access token <a class="header-anchor" href="#一、后台定时获取并刷新微信公众号access-token" aria-hidden="true">#</a></h3><ol><li>安装request和request-promise模块</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install request request</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">promise</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>调用微信接口获取accesstoken保存在后台并且及时刷新</li></ol><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> rq </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">request-promise</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> fs </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">fs</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> file_path </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> __dirname </span><span style="color:#89DDFF;">+</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">/token_file/accessToken.json</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> APPID </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">wxeaf6f9a5e5b669b8</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> APPSECRET </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">6386bad5201d9797b0fa53a96ecead06</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">let</span><span style="color:#A6ACCD;"> uri </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">APPID</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">&amp;secret=</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">APPSECRET</span><span style="color:#89DDFF;">}`</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> updateAccessToken </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;">// 请求微信接口获取token </span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resAccessToken</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">rq</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">uri</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">fomateToken</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">JSON</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">parse</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">resAccessToken</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">expireTime</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">new</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">Date</span><span style="color:#F07178;">()</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">getTime</span><span style="color:#F07178;">() </span><span style="color:#89DDFF;">+</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">fomateToken</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">expires_in</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">*</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">1000</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">fomateToken</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">expireTime</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">expireTime</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">fs</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">writeFileSync</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">file_path</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">JSON</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">stringify</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">fomateToken</span><span style="color:#F07178;">))</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> getAccessToken </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;">// 获取本地存储的accessToken</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">localToken</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">fs</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">readFileSync</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">file_path</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">utf8</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#89DDFF;">  </span><span style="color:#676E95;">// 判断本地token是否过期</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">localTokenFormate</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">JSON</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">parse</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">localToken</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">nowTime</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">new</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">Date</span><span style="color:#F07178;">()</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">getTime</span><span style="color:#F07178;">()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resultToken</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;&#39;</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">nowTime</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">-</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">localTokenFormate</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">expireTime</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&gt;=</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">0</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">updateAccessToken</span><span style="color:#F07178;">()</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">getAccessToken</span><span style="color:#F07178;">()</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span><span style="color:#89DDFF;">else</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">resultToken</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">localTokenFormate</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">access_token</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">return</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resultToken</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">setInterval</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">()</span><span style="color:#C792EA;">=&gt;</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#82AAFF;">getAccessToken</span><span style="color:#F07178;">()</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">then</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">res</span><span style="color:#F07178;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">accessToke===&gt;</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">res</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#89DDFF;">},</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">7200</span><span style="color:#89DDFF;">*</span><span style="color:#F78C6C;">1000</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span></code></pre></div></details><h2 id="第五课、自定义公众号菜单" tabindex="-1">第五课、自定义公众号菜单 <a class="header-anchor" href="#第五课、自定义公众号菜单" aria-hidden="true">#</a></h2><blockquote><p>自定义微信公众号菜单栏，新增、删除、更新click、view以及小程序类型的公众号菜单</p></blockquote><h3 id="一、调用微信公众号接口实现自定义菜单栏" tabindex="-1">一、调用微信公众号接口实现自定义菜单栏 <a class="header-anchor" href="#一、调用微信公众号接口实现自定义菜单栏" aria-hidden="true">#</a></h3><ol><li><p>优化代码—提取公共方法，提取validateWechatHost.js公共方法</p></li><li><p>调用微信公众号接口自定义菜单栏</p></li></ol><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> rq </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">request-promise</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> getAccessToken </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./getWechatAccessToken</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> creatMenue </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">accessToken</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">getAccessToken</span><span style="color:#F07178;">()</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">accessToken===&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">accessToken</span><span style="color:#F07178;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">rqParam</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">button</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;">[</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">    </span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">type</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">click</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">吃饭票</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">key</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">chifanpiao</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">购物票</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">sub_button</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;">[</span></span>
<span class="line"><span style="color:#F07178;">          </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">    </span></span>
<span class="line"><span style="color:#F07178;">              </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">type</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">view</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">              </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">优惠优选</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">              </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">url</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">http://www.soso.com/</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#F07178;">          </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;">          </span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">    </span></span>
<span class="line"><span style="color:#F07178;">              </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">type</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">view</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">              </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">name</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">解析返现</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">              </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">url</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">https://www.bilibili.com/</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#F07178;">          </span><span style="color:#89DDFF;">},</span></span>
<span class="line"><span style="color:#F07178;">        ]</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">    ]</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">param</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    method</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">POST</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">    uri</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;"> https://api.weixin.qq.com/cgi-bin/menu/create?access_token=</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">accessToken</span><span style="color:#89DDFF;">}`</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">    body</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">rqParam</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">    json</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#FF9CAC;">true</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">res</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">rq</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">post</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">param</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">res===&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">res</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">creatMenue</span><span style="color:#A6ACCD;">()</span></span>
<span class="line"></span></code></pre></div></details><h2 id="第六课、微信公众号消息、事件接收" tabindex="-1">第六课、微信公众号消息、事件接收 <a class="header-anchor" href="#第六课、微信公众号消息、事件接收" aria-hidden="true">#</a></h2><blockquote><p>这节课通过koa-body插件解析微信公众号发送过来的POST请求，通过xml2js中间件解析微信服务器发送过来的xml数据包</p></blockquote><h3 id="一、安装koa-body解析微信公众号服务器发送post请求数据" tabindex="-1">一、安装koa-body解析微信公众号服务器发送post请求数据 <a class="header-anchor" href="#一、安装koa-body解析微信公众号服务器发送post请求数据" aria-hidden="true">#</a></h3><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install koa</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">body</span></span>
<span class="line"></span></code></pre></div><h3 id="二、安装xml2js解析微信公众号服务器发送过来的xml数据" tabindex="-1">二、安装xml2js解析微信公众号服务器发送过来的xml数据 <a class="header-anchor" href="#二、安装xml2js解析微信公众号服务器发送过来的xml数据" aria-hidden="true">#</a></h3><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install xml2js</span></span>
<span class="line"></span></code></pre></div><h3 id="三、index-js的原代码" tabindex="-1">三、index.js的原代码 <a class="header-anchor" href="#三、index-js的原代码" aria-hidden="true">#</a></h3><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koa </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> app </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">koa</span><span style="color:#A6ACCD;">()</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koaBody </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">koa-body</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> xml2js </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">xml2js</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> validateWechatHost </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./utils/validateWechatHost</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#82AAFF;">koaBody</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">json</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;">ctx</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">validateWechatHost</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">method</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">GET</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">isWechatHost</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">echostr</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span><span style="color:#89DDFF;">else</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">method</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">POST</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">isWechatHost</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xml2js</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">parseStringPromise</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">to do other things</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">xml</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">for</span><span style="color:#F07178;">(</span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">in</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;">] </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;">][</span><span style="color:#F78C6C;">0</span><span style="color:#F07178;">]</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">xmlJson</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;&#39;</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">listen</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">serve is on at 8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span></code></pre></div></details><h2 id="第七课、微信公众号消息、事件的回复" tabindex="-1">第七课、微信公众号消息、事件的回复 <a class="header-anchor" href="#第七课、微信公众号消息、事件的回复" aria-hidden="true">#</a></h2><blockquote><p>提取公共方法回复微信公众号文本类型和图文类型的消息</p></blockquote><h3 id="一、createresdate源码" tabindex="-1">一、createResDate源码 <a class="header-anchor" href="#一、createresdate源码" aria-hidden="true">#</a></h3><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#676E95;">/**</span></span>
<span class="line"><span style="color:#676E95;"> * 1、接收发送的内容</span></span>
<span class="line"><span style="color:#676E95;"> * 2、接收发送的消息类型</span></span>
<span class="line"><span style="color:#676E95;"> */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> createResData </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">commData</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">&lt;xml&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">  &lt;ToUserName&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">FromUserName</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/ToUserName&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">  &lt;FromUserName&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">ToUserName</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/FromUserName&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">  &lt;CreateTime&gt;</span><span style="color:#89DDFF;">${</span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">Date</span><span style="color:#A6ACCD;">()</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">getTime</span><span style="color:#A6ACCD;">()</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">&lt;/CreateTime&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">  &lt;MsgType&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">type</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/MsgType&gt;</span><span style="color:#89DDFF;">`</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">newsItem</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;&#39;</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">type</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">news</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">content</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">forEach</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">element</span><span style="color:#F07178;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">newsItem</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">+=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">&lt;item&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">      &lt;Title&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">element</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">title</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/Title&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">      &lt;Description&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">element</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">description</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/Description&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">      &lt;PicUrl&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">element</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">picurl</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/PicUrl&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">      &lt;Url&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">element</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">url</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/Url&gt;</span></span>
<span class="line"><span style="color:#C3E88D;">    &lt;/item&gt;</span><span style="color:#89DDFF;">`</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">typeMap</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">text</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">&lt;Content&gt;&lt;![CDATA[</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">content</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">]]&gt;&lt;/Content&gt;</span><span style="color:#89DDFF;">`</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;">news</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">&lt;ArticleCount&gt;</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">count</span><span style="color:#89DDFF;">}</span><span style="color:#C3E88D;">&lt;/ArticleCount&gt;&lt;Articles&gt;</span><span style="color:#89DDFF;">`</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">+</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">newsItem</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">+</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">&lt;/Articles&gt;</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">return</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">commData</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">+</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">typeMap</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">type</span><span style="color:#F07178;">] </span><span style="color:#89DDFF;">+</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">&lt;/xml&gt;</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">exports.</span><span style="color:#A6ACCD;">createResData </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> createResData</span></span>
<span class="line"></span></code></pre></div></details><h3 id="二、index-js源码" tabindex="-1">二、index.js源码 <a class="header-anchor" href="#二、index-js源码" aria-hidden="true">#</a></h3><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koa </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> app </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">koa</span><span style="color:#A6ACCD;">()</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koaBody </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">koa-body</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> xml2js </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">xml2js</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> validateWechatHost </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./utils/validateWechatHost</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;"> createResData </span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./utils/createRespondData</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#82AAFF;">koaBody</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">json</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;">ctx</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">validateWechatHost</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">method</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">GET</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">isWechatHost</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">echostr</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span><span style="color:#89DDFF;">else</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">method</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">POST</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">isWechatHost</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xml2js</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">parseStringPromise</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">xml</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">for</span><span style="color:#F07178;">(</span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">in</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;">] </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;">][</span><span style="color:#F78C6C;">0</span><span style="color:#F07178;">]</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">xmlJson</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;">// xmlJson.type = &#39;text&#39;</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;">// xmlJson.content = &#39;这里是学习资料哦哦哦&#39;</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">type</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">news</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">content</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> [</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">        title</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">波波科技测试</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">        description</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">波波科技测试</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">        picurl</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1115%2F101021113337%2F211010113337-6-1200.jpg&amp;refer=http%3A%2F%2Fimg.jj20.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1654594035&amp;t=6e5217870597b6df9d6d0d7af1ebd452</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">        url</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Passive_user_reply_message.html#5</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">    ]</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">count</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">1</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resMsg</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">createResData</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resMsg</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">listen</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">serve is on at 8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span></code></pre></div></details><h2 id="第八课、-微信公众号对接淘宝客系统配置" tabindex="-1">第八课、 微信公众号对接淘宝客系统配置 <a class="header-anchor" href="#第八课、-微信公众号对接淘宝客系统配置" aria-hidden="true">#</a></h2><blockquote><p>淘宝客逻辑介绍、配置淘宝客api账号</p></blockquote><h3 id="一、淘宝客简介" tabindex="-1">一、淘宝客简介 <a class="header-anchor" href="#一、淘宝客简介" aria-hidden="true">#</a></h3><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-14-090144.png" alt=""></p><h3 id="二、创建淘宝联盟pid" tabindex="-1">二、创建淘宝联盟PID <a class="header-anchor" href="#二、创建淘宝联盟pid" aria-hidden="true">#</a></h3><p><strong>1、注册淘宝联盟账号</strong></p><p>1）进入<a href="http://pub.alimama.com/" target="_blank" rel="noreferrer">淘宝联盟官网</a>，选择“淘宝会员”用淘宝账号和密码登录。</p><p><img src="http://sr.ffquan.com/yunying/0424114213bbc41379326241ae1e9f3d" alt=""></p><p>2）首次登录淘宝联盟的账号需补全信息和身份认证，按照如下步骤填写邮箱进行激活。</p><p><img src="http://sr.ffquan.com/yunying/7761245007c528bebefded9b6a6e8014" alt=""></p><p>3）激活注册邮箱后，进行身份认证。</p><p><img src="http://sr.ffquan.com/yunying/121425edd12eb68c6a206e20e1d2582d" alt=""></p><p>4）身份验证成功则账号激活，激活1小时后再行推广商品，否者推广将无效。</p><p><img src="http://sr.ffquan.com/yunying/41bf6b50a87b8a70cdf1f62b5aa6f04f" alt=""></p><p><strong>2、完成媒体备案</strong></p><p>1）社群推广选择他方平台，如有自己的平台/没有经营地就选择自由平台/无自由阵地（以下按照他方平台介绍）</p><p><img src="http://sr.ffquan.com/yunying/765d759e1133f5a6ed9cfab6fd8ba592" alt=""></p><p>2）选择流量平台，微信/qq等推广选择社交平台。</p><p><img src="http://sr.ffquan.com/yunying/dcc320fbe74210965cfd357e28109b8b" alt=""></p><p>3）填写备案信息</p><p>按照所列信息进行填写，点击下一步即可。（账号id：如微信则填写微信号，qq则填写qq号）</p><p><img src="http://sr.ffquan.com/yunying/1bde06119a4def1f5081378d3d68fae3" alt=""></p><p>4）审核通过后，即可在媒体备案管理查看备案信息。</p><p><img src="http://sr.ffquan.com/yunying/d5ab243618e892ed33f94a0760d54d91" alt=""></p><p><img src="http://sr.ffquan.com/yunying/9c4e28ff8e06e44f2ea2ed7b0e57a902" alt=""></p><p><strong>3、设置推广位</strong></p><p>1）选择“推广位管理-新增推广位”，选择“媒体类型”“媒体名称”“推广位名称”（填写方便区分的名称即可）的信息，点击确定即可。</p><p><img src="http://sr.ffquan.com/yunying/66c2a163c2a46fba45354c048e9d6669" alt=""></p><p>2）获取PID：点击推广位管理，即可复制创建的PID。</p><p><img src="http://sr.ffquan.com/yunying/3cbe2f4711e2b5983a63cd3210deb774" alt=""></p><h3 id="三、大淘客平台设置pid" tabindex="-1">三、大淘客平台设置PID <a class="header-anchor" href="#三、大淘客平台设置pid" aria-hidden="true">#</a></h3><p><strong>1、进入</strong><a href="https://www.dataoke.com/pmc/deploy-pid.html" target="_blank" rel="noreferrer"><strong>大淘客官网</strong></a><strong>→淘宝授权</strong></p><p>绑定PID前首先需要使用自己的淘宝账号进行授权。</p><p><img src="http://sr.ffquan.com/yunying/782bd54d9e40d29286c60c219ac6cdab" alt=""></p><p><strong>2、配置大淘客官网PID</strong></p><p>1）用途</p><p>配置大淘客官方的PID，用于推广商品库、实时榜单、咚咚抢、品牌优惠券、专辑市场的商品。</p><p>2）步骤</p><p>选择新增PID→淘宝联盟（链接 如何获取PID）复制PID粘贴→对PID进行备注（名称用于识别不同的PID，自主决定）</p><p><img src="http://sr.ffquan.com/yunying/92bedb92438dd38f3c95e1087f9ed2fb" alt=""></p><p><strong>3、配置其他板块PID</strong></p><p>如要使用淘礼金、推广小工具、大淘客联盟APP以及开放平台，则在对应板块配置PID即可，按如上“配置大淘客官网PID”步骤进行配置即可。（建议可全部设置）</p><p><img src="http://sr.ffquan.com/yunying/51654be5c23f05bac9139332b075fb19" alt=""></p><h2 id="第九课、-微信公众号调用淘宝联盟接口实现自动找券" tabindex="-1">第九课、 微信公众号调用淘宝联盟接口实现自动找券 <a class="header-anchor" href="#第九课、-微信公众号调用淘宝联盟接口实现自动找券" aria-hidden="true">#</a></h2><blockquote><p>通过调用淘宝联盟的接口实现找券系统的自动找券回复功能</p></blockquote><h3 id="一、引入大淘客sdk在nodejs中调用淘宝接口" tabindex="-1">一、引入大淘客sdk在nodejs中调用淘宝接口 <a class="header-anchor" href="#一、引入大淘客sdk在nodejs中调用淘宝接口" aria-hidden="true">#</a></h3><ol><li>安装sdk模块, <a href="https://www.dataoke.com/" target="_blank" rel="noreferrer">大淘客官网</a></li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install dtk</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">nodejs</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">api</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">sdk</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>调用示例, <a href="https://www.dataoke.com/kfpt/open-gz.html?id=108" target="_blank" rel="noreferrer">参考网址</a></li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> dtkSdk </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">dtk-nodejs-api-sdk</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#676E95;">/*</span></span>
<span class="line"><span style="color:#676E95;"> *  @checkSign: 1 默认老版本验签  2 新版验签</span></span>
<span class="line"><span style="color:#676E95;"> *  @appKey: 用户填写 appkey</span></span>
<span class="line"><span style="color:#676E95;"> *  @appSecret: 用户填写 appSecret</span></span>
<span class="line"><span style="color:#676E95;"> */</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> sdk </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">dtkSdk</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">appKey</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;">appSecret</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;">checkSign</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> getBrandList </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> sdk</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">request</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">接口地址</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,{</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">method</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">GET</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#676E95;">/* 注意:form 里面就不用传appKey与appSecret  */</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">form</span><span style="color:#89DDFF;">:{</span><span style="color:#F07178;">pageId</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">1</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;">pageSize</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">20</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">v1.1.0</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">then</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">)</span><span style="color:#C792EA;">=&gt;</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">res</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">接口调用成功</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#89DDFF;">},(</span><span style="color:#A6ACCD;">error</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">body</span><span style="color:#89DDFF;">)</span><span style="color:#C792EA;">=&gt;</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">error</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">接口调用失败</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span></code></pre></div><h3 id="二、源码笔记" tabindex="-1">二、源码笔记 <a class="header-anchor" href="#二、源码笔记" aria-hidden="true">#</a></h3><ol><li>index.js源码</li></ol><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koa </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> app </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">koa</span><span style="color:#A6ACCD;">()</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> koaBody </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">koa-body</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> xml2js </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">xml2js</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> validateWechatHost </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./utils/validateWechatHost</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;"> createResData </span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./utils/createRespondData</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;"> getTaoBaoPro </span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./utils/getTaoBaoProduct</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#82AAFF;">koaBody</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">json</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#FF9CAC;">true</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">))</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;">ctx</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">validateWechatHost</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">method</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">GET</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">isWechatHost</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">echostr</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span><span style="color:#89DDFF;">else</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">method</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">==</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">POST</span><span style="color:#89DDFF;">&quot;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">validateRes</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">isWechatHost</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xml2js</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">parseStringPromise</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">request</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlString</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">xml</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">for</span><span style="color:#F07178;">(</span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">in</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;">] </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlTemp</span><span style="color:#F07178;">[</span><span style="color:#A6ACCD;">item</span><span style="color:#F07178;">][</span><span style="color:#F78C6C;">0</span><span style="color:#F07178;">]</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">xmlJson</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">MsgType</span><span style="color:#89DDFF;">===</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">event</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&amp;&amp;</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">EventKey</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">===</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">chifanpiao</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">type</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">news</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">content</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> [</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">          title</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">波波科技测试</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">          description</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">波波科技测试</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">          picurl</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1115%2F101021113337%2F211010113337-6-1200.jpg&amp;refer=http%3A%2F%2Fimg.jj20.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1654594035&amp;t=6e5217870597b6df9d6d0d7af1ebd452</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#F07178;">          url</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Passive_user_reply_message.html#5</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">      ]</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">count</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">1</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">else</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">MsgType</span><span style="color:#89DDFF;">===</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">text</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#89DDFF;">      </span><span style="color:#676E95;">// 查询淘宝官方接口，返回商品返现和优惠券详情逻辑</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">getTaoBaoPro</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">Content</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">formateProductInfo</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;&#39;</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">couponInfo</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">!==</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">0</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">||</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">returnMoney</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">formateProductInfo</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">优惠券：</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">couponInfo</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">\n</span><span style="color:#C3E88D;">券后价格：</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">price</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">\n</span><span style="color:#C3E88D;">额外返现：</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">returnMoney</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">\n</span><span style="color:#C3E88D;">----------------</span><span style="color:#A6ACCD;">\n</span><span style="color:#89DDFF;">${</span><span style="color:#A6ACCD;">taobaoPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">longTpwd</span><span style="color:#89DDFF;">}`</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">}</span><span style="color:#89DDFF;">else</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">formateProductInfo</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">亲，该商家无活动哦！</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">type</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">text</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">      </span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">content</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">formateProductInfo</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resMsg</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">createResData</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">xmlJson</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">ctx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">body</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resMsg</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">listen</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">serve is on at 8080</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"></span></code></pre></div></details><ol start="2"><li>获取淘宝返现和优惠券源码</li></ol><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> dtkSdk </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">dtk-nodejs-api-sdk</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#676E95;">/*</span></span>
<span class="line"><span style="color:#676E95;"> *  @checkSign: 1 默认老版本验签  2 新版验签</span></span>
<span class="line"><span style="color:#676E95;"> *  @appKey: 用户填写 appkey</span></span>
<span class="line"><span style="color:#676E95;"> *  @appSecret: 用户填写 appSecret</span></span>
<span class="line"><span style="color:#676E95;"> */</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> APP_KEY </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">6283b426623d1</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> APP_SECRET </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">d69c72bc2519f7b04f2f080e6107a18e</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> sdk </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">dtkSdk</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">{</span><span style="color:#F07178;">appKey</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> APP_KEY</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">appSecret</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> APP_SECRET</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">checkSign</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">2</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">)</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#C792EA;">let</span><span style="color:#A6ACCD;"> URL </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">`</span><span style="color:#C3E88D;">https://openapi.dataoke.com/api/tb-service/twd-to-twd</span><span style="color:#89DDFF;">`</span></span>
<span class="line"><span style="color:#C792EA;">let</span><span style="color:#A6ACCD;"> taobaoProInfor </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">couponInfo</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;">// 优惠券</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">price</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;">// 券后价格</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">returnMoney</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;">// 额外返现</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">longTpwd</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;">// 淘口令</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> getTaoBaoPro </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">async</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">content</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">=&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productInfo</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">await</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">sdk</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">request</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">URL</span><span style="color:#89DDFF;">,{</span><span style="color:#F07178;">method</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">GET</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;">form</span><span style="color:#89DDFF;">:{</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">v1.0.0</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">content</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">}}</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#C792EA;">let</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productData</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productInfo</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">data</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">if</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;">productData</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">taobaoProInfor</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">couponInfo</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productData</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">originalPrice</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">-</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productData</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">actualPrice</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">taobaoProInfor</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">longTpwd</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productData</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">longTpwd</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">taobaoProInfor</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">price</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">productData</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">actualPrice</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">taobaoProInfor</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">returnMoney</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> ((</span><span style="color:#A6ACCD;">productData</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">actualPrice</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">*</span><span style="color:#F07178;"> (</span><span style="color:#A6ACCD;">productData</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">maxCommissionRate</span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">100</span><span style="color:#F07178;">)) </span><span style="color:#89DDFF;">*</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">0.9</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">toFixed</span><span style="color:#F07178;">(</span><span style="color:#F78C6C;">2</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span><span style="color:#89DDFF;">else</span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#A6ACCD;">taobaoProInfor</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">=</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">      couponInfo</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#676E95;">// 优惠券</span></span>
<span class="line"><span style="color:#F07178;">      price</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">0</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#676E95;">// 券后价格</span></span>
<span class="line"><span style="color:#F07178;">      returnMoney</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#676E95;">// 额外返现</span></span>
<span class="line"><span style="color:#F07178;">      longTpwd</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&#39;&#39;</span><span style="color:#F07178;"> </span><span style="color:#676E95;">// 淘口令</span></span>
<span class="line"><span style="color:#F07178;">    </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">console</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">log</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">taobaoProInfor===&gt;</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">taobaoProInfor</span><span style="color:#F07178;">)</span></span>
<span class="line"><span style="color:#F07178;">  </span><span style="color:#89DDFF;">return</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">taobaoProInfor</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">exports.</span><span style="color:#A6ACCD;">getTaoBaoPro </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> getTaoBaoPro</span></span>
<span class="line"></span></code></pre></div></details><h2 id="第十课、微信公众号部署到阿里云服务器-服务器配置" tabindex="-1">第十课、微信公众号部署到阿里云服务器(服务器配置) <a class="header-anchor" href="#第十课、微信公众号部署到阿里云服务器-服务器配置" aria-hidden="true">#</a></h2><blockquote><p>微信公众号部署到服务(以阿里云服务器为例)，配置服务器的nodejs、域名解析、nginx以及pm2</p></blockquote><h3 id="一、-注册并购买好阿里云服务" tabindex="-1">一、 注册并购买好阿里云服务 <a class="header-anchor" href="#一、-注册并购买好阿里云服务" aria-hidden="true">#</a></h3><ol><li><p><a href="https://ecs-buy.aliyun.com/wizard/#/prepay/cn-hongkong?fromDomain=true" target="_blank" rel="noreferrer">官网地址</a>购买服务器，购买时的密码一定要记住</p></li><li><p>选择香港的服务器，可以免备案</p></li></ol><h3 id="二、下载filezilla，用于批量上传文件到服务器" tabindex="-1">二、下载FileZilla，用于批量上传文件到服务器 <a class="header-anchor" href="#二、下载filezilla，用于批量上传文件到服务器" aria-hidden="true">#</a></h3><blockquote><p>下载地址<a href="https://www.filezilla.cn/download" target="_blank" rel="noreferrer">FileZilla</a>，用于文件传输的端口好一般是22</p></blockquote><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-22-135621.png" alt=""></p><h3 id="三、安装好服务器的nodejs环境" tabindex="-1">三、安装好服务器的nodejs环境 <a class="header-anchor" href="#三、安装好服务器的nodejs环境" aria-hidden="true">#</a></h3><ol><li>nodejs 官网下载好linux版本的安装包</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-22-133822.png" alt=""></p><ol start="2"><li>通过FileZilla将下载好的nodejs包上传到服务器</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-22-140053.png" alt=""></p><ol start="3"><li>用ssh登录到服务器后台</li></ol><blockquote><p>如果远程服务器重装了系统链接报错：has changed and you have requested strict checking.。此时需要强制清除你当前机器里关于你的远程服务器的缓存和公钥信息, 终端中运行如下命令</p><p><code>ssh-keygen -R &quot;你的远程服务器ip地址&quot;</code></p></blockquote><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#676E95;">// ssh 登录账号@服务器ip地址</span></span>
<span class="line"><span style="color:#A6ACCD;">ssh root@</span><span style="color:#F78C6C;">8.218</span><span style="color:#89DDFF;">.</span><span style="color:#F78C6C;">53.95</span></span>
<span class="line"></span></code></pre></div><ol start="4"><li>解压安装nodejs 并软连接到/urs/bin目录</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#676E95;">// 1. 解压nodejs包</span></span>
<span class="line"><span style="color:#A6ACCD;">tar xvf node</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v16</span><span style="color:#89DDFF;">.</span><span style="color:#F78C6C;">15.0</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">linux</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">x64</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">xz</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">// 2.解压完成后重命名文件夹，将文件夹重命名为nodejs，方便管理</span></span>
<span class="line"><span style="color:#A6ACCD;">mv node</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v16</span><span style="color:#89DDFF;">.</span><span style="color:#F78C6C;">15.0</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">linux</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">x64 nodejs</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">// 3. 将nodejs 目录拷贝到/urs/local目录下</span></span>
<span class="line"><span style="color:#A6ACCD;">cp </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">r nodejs </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">local</span><span style="color:#89DDFF;">/</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">// 4. 软连接到系统的bin目录下</span></span>
<span class="line"><span style="color:#A6ACCD;">ln </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">s </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">home</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nodejs</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">node </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">local</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">node </span></span>
<span class="line"><span style="color:#A6ACCD;">ln </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">s </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">home</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nodejs</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">npm </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">local</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">npm</span></span>
<span class="line"><span style="color:#A6ACCD;">ln </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">s </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">home</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nodejs</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">npx </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">local</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">npx</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">// 5.安装nodejs服务器的后台管理模块 pm2</span></span>
<span class="line"><span style="color:#A6ACCD;">npm install </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">g pm2</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">// 6.将pm2模块软连接到系统的/usr/local/bin目录下</span></span>
<span class="line"><span style="color:#A6ACCD;">ln </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">s </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">home</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nodejs</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">node_modules</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">pm2</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">pm2 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">local</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span></span>
<span class="line"></span></code></pre></div><h3 id="四、安装ngnix服务" tabindex="-1">四、安装ngnix服务 <a class="header-anchor" href="#四、安装ngnix服务" aria-hidden="true">#</a></h3><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">、</span><span style="color:#FFCB6B;">安装nginx</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;">   yum install nginx</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;">、 进入nginx 目录 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sbin执行命令启动：  </span><span style="color:#89DDFF;">./</span><span style="color:#A6ACCD;">nginx</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F78C6C;">3</span><span style="color:#A6ACCD;">、</span><span style="color:#82AAFF;">nginx配置文件</span><span style="color:#A6ACCD;">(nginx</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf)目录：</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nginx</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F78C6C;">4</span><span style="color:#A6ACCD;">、nginx的其他相关操作</span></span>
<span class="line"><span style="color:#A6ACCD;">nginx </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">s </span><span style="color:#FFCB6B;">reload</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> 重启nginx </span></span>
<span class="line"><span style="color:#A6ACCD;">nginx </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">t： 检查nginx配置是否正确</span></span>
<span class="line"></span></code></pre></div><h3 id="五、配置域名解析" tabindex="-1">五、配置域名解析 <a class="header-anchor" href="#五、配置域名解析" aria-hidden="true">#</a></h3><ol><li><p>买个便宜的域名<a href="https://wanwang.aliyun.com/domain/searchresult/?keyword=bobokeji&amp;suffix=.xyz#?keyword=bobokejiwangluo&amp;suffix=xyz" target="_blank" rel="noreferrer">域名信息</a>，做好域名的实名认证</p></li><li><p>配置好域名解析,同时也要配置好(安全组)防火墙开发80、443端口</p></li></ol><p><code>域名解析</code></p><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-24-141715.png" alt=""></p><p><code>安全组(防火墙)配置，开放80和443端口、同时把我们自己开发的服务器端口8080也开放</code></p><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-24-142509.png" alt=""></p><h2 id="第十一课、微信公众号部署到阿里云服务器-公众号配置" tabindex="-1">第十一课、微信公众号部署到阿里云服务器(公众号配置) <a class="header-anchor" href="#第十一课、微信公众号部署到阿里云服务器-公众号配置" aria-hidden="true">#</a></h2><blockquote><p>微信公众号实战项目部署到服务器，公众号ip白名单设置、服务器验证配置</p></blockquote><h3 id="一、ip白名单配置" tabindex="-1">一、ip白名单配置 <a class="header-anchor" href="#一、ip白名单配置" aria-hidden="true">#</a></h3><blockquote><p>把我们需要部署到的服务器的ip配置到白名单，这样才能获取到公众号的accesstoken</p></blockquote><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-24-144255.png" alt=""></p><h3 id="二、node服务中的微信公众号appid改成需要上线的公众号appid" tabindex="-1">二、node服务中的微信公众号appid改成需要上线的公众号appid <a class="header-anchor" href="#二、node服务中的微信公众号appid改成需要上线的公众号appid" aria-hidden="true">#</a></h3><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-24-150623.png" alt=""></p><h3 id="三、通过filezilla把开发好的微信公众号找券系统代码上传到服务器" tabindex="-1">三、通过FileZilla把开发好的微信公众号找券系统代码上传到服务器 <a class="header-anchor" href="#三、通过filezilla把开发好的微信公众号找券系统代码上传到服务器" aria-hidden="true">#</a></h3><p>我们把文件上传到服务器的 <strong>/home/bobokeji_nodejs_backEnd</strong>目录下</p><h3 id="四、服务器的一些基本操作指令" tabindex="-1">四、服务器的一些基本操作指令 <a class="header-anchor" href="#四、服务器的一些基本操作指令" aria-hidden="true">#</a></h3><ol><li>Linux 基本命令</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">    链接远端服务器： ssh root@服务器ip</span></span>
<span class="line"><span style="color:#A6ACCD;">    密码：shsfdssdf</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    查看服务器系统版本号： lsb_release </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">a</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    删除文件： rm     删除文件夹 rm </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">rf </span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    查找文件目录： whereis nix</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    从根目录查找文件： find </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">name xxxx</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    显示当前目录： pwd　　</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    查询端口使用情况： netstat </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ntlp</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    vim 打开服务器文件并编辑： vim fileName</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    新建文件夹： mkdir fileName</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    一个文件复制到另一个文件夹下： cp 文件A路径  目标路径</span></span>
<span class="line"><span style="color:#A6ACCD;">    一个文件移动到另一本文件夹下：mv 源文件目录   目标目录</span></span>
<span class="line"><span style="color:#A6ACCD;">    查看当前目录的绝对路径： pwd</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>Vim 文件编辑相关操作(所有命令需要在英文状态下)</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">命令模式：</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">dd</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> 删除光标所在行</span></span>
<span class="line"><span style="color:#A6ACCD;">    :q  退出文件查看</span></span>
<span class="line"><span style="color:#A6ACCD;">    :wq  保存并退出文件</span></span>
<span class="line"><span style="color:#A6ACCD;">    gg  跳到首行第一个字符</span></span>
<span class="line"><span style="color:#A6ACCD;">    shift </span><span style="color:#89DDFF;">+</span><span style="color:#A6ACCD;"> g 跳到末行</span></span>
<span class="line"><span style="color:#82AAFF;">按以下键进入编辑模式</span><span style="color:#A6ACCD;">(esc推出编辑模式)：</span></span>
<span class="line"><span style="color:#A6ACCD;">    i：在当前字符前插入。</span></span>
<span class="line"><span style="color:#A6ACCD;">    I：在光标所在行的行首插入。</span></span>
<span class="line"><span style="color:#A6ACCD;">    a：在当前字符后插入。</span></span>
<span class="line"><span style="color:#A6ACCD;">    A：在光标所在行的行尾插入。</span></span>
<span class="line"><span style="color:#A6ACCD;">    o：在当前行的下一行插入新的一行。</span></span>
<span class="line"><span style="color:#A6ACCD;">    O：在当前行的上一行插入新的 一行。</span></span>
<span class="line"><span style="color:#A6ACCD;">    set nu ：显示行号</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F78C6C;">32</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">65d：删除32</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">65行</span></span>
<span class="line"></span></code></pre></div><ol start="3"><li>pm2相关命令</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">    pm2 start app</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">js           # 启动app</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">js应用程序</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 start app</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">js </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">api</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> # 启动应用程序并命名为 </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">api</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 list                          # 列表 PM2 启动的所有的应用程序</span></span>
<span class="line"><span style="color:#A6ACCD;">     pm2 monit                     # 显示每个应用程序的CPU和内存占用情况</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 logs                       # 显示所有应用程序的日志</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 stop all                  # 停止所有的应用程序</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 show [app</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">name]          # 显示应用程序的所有信息</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 </span><span style="color:#89DDFF;">delete</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;">                  # 删除指定应用 id </span><span style="color:#F78C6C;">0</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 restart xxx     #重启应用 xxx为开启的名称</span></span>
<span class="line"><span style="color:#A6ACCD;">    pm2 stop xxx     #停止应用 xxx为开启的名称</span></span>
<span class="line"></span></code></pre></div><h3 id="五、在线npm-install安装需要的依赖" tabindex="-1">五、在线<code>npm install</code>安装需要的依赖 <a class="header-anchor" href="#五、在线npm-install安装需要的依赖" aria-hidden="true">#</a></h3><blockquote><p>进入我们上传好的文件目录：<strong>/home/bobokeji_nodejs_backEnd</strong>中，执行npm install 安装完成后会在此目录生成node_modules目录</p></blockquote><h3 id="六、使用pm2启动并监听node服务" tabindex="-1">六、使用pm2启动并监听node服务 <a class="header-anchor" href="#六、使用pm2启动并监听node服务" aria-hidden="true">#</a></h3><ol><li>ngnix配置接口转发</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">proxy_pass </span><span style="color:#FFCB6B;">http</span><span style="color:#89DDFF;">:</span><span style="color:#676E95;">//127.0.0.1:8080/;</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>pm2 start index.js --name=&quot;index&quot; 启动服务器</li></ol><h3 id="七、微信公众平台配置好服务器验证" tabindex="-1">七、微信公众平台配置好服务器验证 <a class="header-anchor" href="#七、微信公众平台配置好服务器验证" aria-hidden="true">#</a></h3><ol><li>微信公众平台配置验证后台服务器</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-25-145721.png" alt=""></p><ol start="2"><li>微信公众平台启用服务器</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-05-25-145934.png" alt=""></p><ol start="3"><li><p>执行脚本<code>operatorMenu.js</code>更新微信公众号的菜单栏</p><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#676E95;">// 个人微信公众号没有创建菜单栏这个接口的权限</span></span>
<span class="line"><span style="color:#A6ACCD;">node operatorMenu</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">js </span></span>
<span class="line"></span></code></pre></div></li><li><p>最后验证一下自动找券功能是否正常</p></li></ol><h2 id="第十二课-ejs模块渲染前端html页面" tabindex="-1">第十二课 ejs模块渲染前端html页面 <a class="header-anchor" href="#第十二课-ejs模块渲染前端html页面" aria-hidden="true">#</a></h2><blockquote><p>koa-router路由访问，koa-views配合ejs服务端渲染，koa-static实现服务端动静分离</p></blockquote><h3 id="一、koa-router实现路由访问" tabindex="-1">一、koa-router实现路由访问 <a class="header-anchor" href="#一、koa-router实现路由访问" aria-hidden="true">#</a></h3><ol><li><p>安装koa-router<code>npm install koa-router</code></p></li><li><p>引入并配置路由</p></li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> Router </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa-router</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> router </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">new</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">Router</span><span style="color:#A6ACCD;">()</span></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(router</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">routes</span><span style="color:#A6ACCD;">())</span></span>
<span class="line"></span></code></pre></div><h3 id="二、koa-views配合ejs服务端渲染" tabindex="-1">二、koa-views配合ejs服务端渲染 <a class="header-anchor" href="#二、koa-views配合ejs服务端渲染" aria-hidden="true">#</a></h3><ol><li>安装koa-views和ejs模块</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install koa</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">views ejs</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>引入并配置koa-views</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#676E95;">// 此处配置需要在路由配置之前</span></span>
<span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> views </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa-views</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#82AAFF;">views</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">./view</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">map</span><span style="color:#89DDFF;">:{</span><span style="color:#89DDFF;">&#39;</span><span style="color:#F07178;">html</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">ejs</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">}</span><span style="color:#A6ACCD;">))</span></span>
<span class="line"></span></code></pre></div><h3 id="三、koa-static实现服务端动静分离" tabindex="-1">三、koa-static实现服务端动静分离 <a class="header-anchor" href="#三、koa-static实现服务端动静分离" aria-hidden="true">#</a></h3><ol><li>安装koa-static模块</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">npm install koa</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">static</span></span>
<span class="line"></span></code></pre></div><ol start="2"><li>引入并配置静态目录</li></ol><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#C792EA;">const</span><span style="color:#A6ACCD;"> static </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">require</span><span style="color:#A6ACCD;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">koa-static</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">use</span><span style="color:#A6ACCD;">(</span><span style="color:#82AAFF;">static</span><span style="color:#A6ACCD;">(path</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">join</span><span style="color:#A6ACCD;">(__dirname</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">/static</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">)))</span></span>
<span class="line"></span></code></pre></div><h2 id="第十三课-nodejs服务-nginx-配置https访问" tabindex="-1">第十三课 nodejs服务 nginx 配置https访问 <a class="header-anchor" href="#第十三课-nodejs服务-nginx-配置https访问" aria-hidden="true">#</a></h2><h3 id="一、-上传代码到服务器" tabindex="-1">一、 上传代码到服务器 <a class="header-anchor" href="#一、-上传代码到服务器" aria-hidden="true">#</a></h3><ol><li><p>上传index.js文件和view目录下的文件</p></li><li><p>服务器安装koa-router koa-views koa-static ejs</p></li></ol><h3 id="二、-阿里云服务起申请免费的https的证书" tabindex="-1">二、 阿里云服务起申请免费的https的证书 <a class="header-anchor" href="#二、-阿里云服务起申请免费的https的证书" aria-hidden="true">#</a></h3><ol><li><p>进入<a href="https://www.aliyun.com/" target="_blank" rel="noreferrer">阿里云官网</a></p></li><li><p>进入控制台搜索证书</p></li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-06-04-070019.png" alt=""></p><ol start="3"><li>点击进入ssl证书---&gt;点击免费证书---&gt;点击创建证书</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-06-04-070200.png" alt=""></p><ol start="4"><li>点击证书申请，填写好对应的域名，等待审批即可</li></ol><p><img src="https://filepics.oss-cn-shenzhen.aliyuncs.com/images/2022-06-04-070439.png" alt=""></p><h3 id="三、nginx配置https访问" tabindex="-1">三、nginx配置https访问 <a class="header-anchor" href="#三、nginx配置https访问" aria-hidden="true">#</a></h3><p><code>nginx配置https验证</code></p><details class="details custom-block"><summary>点击这里查看源码</summary><div class="language-javascript"><button title="Copy Code" class="copy"></button><span class="lang">javascript</span><pre><code><span class="line"><span style="color:#A6ACCD;">server </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">                </span><span style="color:#A6ACCD;">listen</span><span style="color:#F07178;"> </span><span style="color:#F78C6C;">80</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">            </span><span style="color:#A6ACCD;">server_name</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">_</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">                </span><span style="color:#A6ACCD;">rewrite</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">^/</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">.*</span><span style="color:#F07178;">)</span><span style="color:#A6ACCD;">$</span><span style="color:#F07178;"> </span><span style="color:#FFCB6B;">https</span><span style="color:#89DDFF;">:</span><span style="color:#676E95;">//$host$1 permanent;</span></span>
<span class="line"><span style="color:#F07178;">       </span><span style="color:#89DDFF;">}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    server </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">listen</span><span style="color:#F07178;">       </span><span style="color:#F78C6C;">443</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">ssl</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">http2</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">default_server</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">listen</span><span style="color:#F07178;">       [::]:</span><span style="color:#F78C6C;">443</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">ssl</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">http2</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">default_server</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">server_name</span><span style="color:#F07178;">  </span><span style="color:#A6ACCD;">_</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">root</span><span style="color:#F07178;">         </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nginx</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">html</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bobokeji</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">ssl_certificate</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">/home/https/7886748_www.bobozhaoquan.cn.pem</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">ssl_certificate_key</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">/home/https/7886748_www.bobozhaoquan.cn.key</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">ssl_session_cache</span><span style="color:#F07178;"> </span><span style="color:#FFCB6B;">shared</span><span style="color:#89DDFF;">:</span><span style="color:#FFCB6B;">SSL</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;">1</span><span style="color:#A6ACCD;">m</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">ssl_session_timeout</span><span style="color:#F07178;">  10</span><span style="color:#A6ACCD;">m</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">ssl_ciphers</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">PROFILE</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">SYSTEM</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">ssl_prefer_server_ciphers</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">on</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">        # </span><span style="color:#A6ACCD;">Load</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">configuration</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">files</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">for</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">the</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">default</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">server</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">block</span><span style="color:#89DDFF;">.</span></span>
<span class="line"><span style="color:#F07178;">        </span><span style="color:#A6ACCD;">include</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">nginx</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">default</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">d</span><span style="color:#676E95;">/*.conf;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">        location / {</span></span>
<span class="line"><span style="color:#676E95;">                proxy_pass http://127.0.0.1:8080/;</span></span>
<span class="line"><span style="color:#676E95;">        }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">        error_page 404 /404.html;</span></span>
<span class="line"><span style="color:#676E95;">            location = /40x.html {</span></span>
<span class="line"><span style="color:#676E95;">            }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;">        error_page 500 502 503 504 /50x.html;</span></span>
<span class="line"><span style="color:#676E95;">            location = /50x.html {</span></span>
<span class="line"><span style="color:#676E95;">        }</span></span>
<span class="line"><span style="color:#676E95;">    }</span></span>
<span class="line"></span></code></pre></div></details></div></div></main><!--[--><!--]--><footer class="VPDocFooter" data-v-37ebe389 data-v-a54a85bd><!----><div class="prev-next" data-v-a54a85bd><div class="pager" data-v-a54a85bd><!----></div><div class="pager" data-v-a54a85bd><a class="pager-link next" href="/bobokejiDoc/jdtext.html" data-v-a54a85bd><span class="desc" data-v-a54a85bd>Next page</span><span class="title" data-v-a54a85bd>公众号开发「京东」返现系统</span></a></div></div></footer><!--[--><!--]--></div></div></div></div></div><footer class="VPFooter has-sidebar" data-v-c6a644e1 data-v-9f24cc86><div class="container" data-v-9f24cc86></div></footer><!--[--><!--]--></div></div>
    <script>__VP_HASH_MAP__ = JSON.parse("{\"index.md\":\"b0598824\",\"jdtext.md\":\"fecc5be2\",\"minpro.md\":\"f3d690b5\",\"tbtext.md\":\"9db7909d\"}")</script>
    <script type="module" async src="/bobokejiDoc/assets/app.d51e1bd1.js"></script>
    
  </body>
</html>